package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.ConversionRecordBean;
import com.lc.pianostudent.bean.PianoRecordBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.JOURNAL_INDEX)
public class PostJournalIndex extends BaseAsyPost {

    public String user_id;//1用户注册

    public PostJournalIndex(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostJournalIndexInfo parser(JSONObject object) throws Exception {

        if (object.optString("code").equals("200")) {

            PostJournalIndexInfo info = new PostJournalIndexInfo();


            info.message = object.optString("message");

            info.code = object.optString("code");

            JSONArray array = object.optJSONArray("data");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    PianoRecordBean pianoRecordBean = new PianoRecordBean();
                    pianoRecordBean.setTime(o.optString("time"));
                    pianoRecordBean.setCreate_time(o.optString("create_time"));
                    pianoRecordBean.setId(o.optString("id"));
                    pianoRecordBean.setNumber(o.optString("number"));
                    pianoRecordBean.setUserid(o.optString("userid"));
                    pianoRecordBean.setWealth(o.optString("wealth"));
                    pianoRecordBean.setXx(o.optString("xx"));
                    pianoRecordBean.setZhixing(o.optString("zhixing"));
                    pianoRecordBean.setRenzhen(o.optString("renzhen"));
                    pianoRecordBean.setText(o.optString("text"));

                    info.list.add(pianoRecordBean);
                }

            }


            TOAST = object.optString("message");

            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostJournalIndexInfo {

        public String message,code;
        public List<PianoRecordBean> list = new ArrayList<>();
    }
}
